package com.yanqu.road.server.cmd.activity.silkroad;

import com.yanqu.road.entity.activity.silkroad.SilkRoadFindResult;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.activity.SilkRoadProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.activity.silkroad.SilkRoadModule;
import com.yanqu.road.server.protocol.ClientProtocol;
import com.yanqu.road.server.protocol.GameProtocol;

@Cmd(code = GameProtocol.S_SILK_ROAD_FIND, desc = "航行")
public class SilkRoadFindCmd extends AbstractCommand {

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {

        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        SilkRoadProto.SilkRoadFindReqMsg reqMsg = SilkRoadProto.SilkRoadFindReqMsg.parseFrom(packet.getBytes());
        SilkRoadFindResult findResult = player.getModule(SilkRoadModule.class).findTreasure(reqMsg.getActivityId(), reqMsg.getNum());
        ret = findResult.getRet();
        if (ret == 0) {
            SilkRoadProto.SilkRoadFindRespMsg.Builder resp = SilkRoadProto.SilkRoadFindRespMsg.newBuilder();
            resp.setRet(0);
            resp.setReward(findResult.getRewards());
            resp.addAllFindStep(findResult.getFindStepList());
            resp.addAllPlaceId(findResult.getPlaceIdList());
            resp.addAllEventId(findResult.getEventIds());
            player.sendPacket(ClientProtocol.U_SILK_ROAD_FIND, resp);
            player.getModule(SilkRoadModule.class).syncUserMsg();
        }
    }

    @Override
    public void sendData(GamePlayer player) {
        if (ret != 0) {
            player.sendPacket(ClientProtocol.U_SILK_ROAD_FIND, SilkRoadProto.SilkRoadFindRespMsg.newBuilder().setRet(ret));
        }
    }
}
